package com.linkstec.mot.base;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

public class ParamDto extends HashMap<String, Object> {

	/**
	 * 给后台调用的Service使用
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public String[] keys()
	/*     */   {
	/*  27 */     return ((String[])keySet().toArray(new String[size()]));
	/*     */   }
	/*     */ 
	/*     */   public void set(String propName, Object obj) {
	/*  31 */     put(propName, obj);
	/*     */   }
	/*     */ 
	/*     */   public void add(String propName, Object obj) {
	/*  35 */     set(propName, getRowCount(propName), obj);
	/*     */   }
	/*     */ 
	/*     */   @SuppressWarnings({ "rawtypes", "unchecked" })
	            public void set(String propName, int index, Object obj) {
	/*  39 */    
	              ArrayList lst = (ArrayList)get(propName);
	/*  40 */     if (lst == null) {
	/*  41 */       lst = new ArrayList();
	/*  42 */       put(propName, lst);
	/*     */     }
	/*     */ 
	/*  45 */     for (int i = lst.size(); i <= index; ++i) {
	/*  46 */       lst.add(null);
	/*     */     }
	/*     */ 
	/*  49 */     lst.set(index, obj);
	/*     */   }
	/*     */ 
	/*     */   @SuppressWarnings("rawtypes")
	public int getRowCount(String propName) {
	/*  53 */     Object obj = get(propName);
	/*  54 */     if (obj == null)
	/*  55 */       return 0;
	/*  56 */     if (obj instanceof ArrayList) {
	/*  57 */       return ((ArrayList)obj).size();
	/*     */     }
	/*  59 */     return -1;
	/*     */   }
	/*     */ 
	/*     */   public Object get(String propName, int index)
	/*     */   {
	/*  64 */     @SuppressWarnings("rawtypes")
	ArrayList lst = (ArrayList)get(propName);
	/*  65 */     if (lst == null) {
	/*  66 */       return null;
	/*     */     }
	/*  68 */     return lst.get(index);
	/*     */   }
	/*     */ 
	/*     */   public ParamDto getBaseDto(String propName)
	/*     */   {
	/*  73 */     return convertToBaseDto(get(propName));
	/*     */   }
	/*     */ 
	/*     */   public ParamDto getBaseDto(String propName, int index) {
	/*  77 */     return convertToBaseDto(get(propName, index));
	/*     */   }
	/*     */ 
	/*     */   public String getString(String propName) {
	/*  81 */     return convertToString(get(propName));
	/*     */   }
	/*     */ 
	/*     */   public String getString(String propName, int index) {
	/*  85 */     return convertToString(get(propName, index));
	/*     */   }
	/*     */ 
	/*     */   public BigDecimal getBigDecimal(String propName) {
	/*  89 */     return convertToBigDecimal(get(propName));
	/*     */   }
	/*     */ 
	/*     */   public BigDecimal getBigDecimal(String propName, int index) {
	/*  93 */     return convertToBigDecimal(get(propName, index));
	/*     */   }
	/*     */ 
	/*     */   public Timestamp getTimestamp(String propName) {
	/*  97 */     return convertToTimestamp(get(propName));
	/*     */   }
	/*     */ 
	/*     */   public Timestamp getTimestamp(String propName, int index) {
	/* 101 */     return convertToTimestamp(get(propName, index));
	/*     */   }
	/*     */ 
	/*     */   public Long getLong(String propName) {
	/* 105 */     return convertToLong(get(propName));
	/*     */   }
	/*     */ 
	/*     */   public Long getLong(String propName, int index) {
	/* 109 */     return convertToLong(get(propName, index));
	/*     */   }
	/*     */ 
	/*     */   private static ParamDto convertToBaseDto(Object obj)
	/*     */   {
	/* 114 */     return ((ParamDto)obj);
	/*     */   }
	/*     */ 
	/*     */   private static String convertToString(Object obj) {
	/* 118 */     if (obj == null)
	/* 119 */       return null;
	/* 120 */     if (obj instanceof String) {
	/* 121 */       return ((String)obj);
	/*     */     }
	/* 123 */     return obj.toString();
	/*     */   }
	/*     */ 
	/*     */   private static BigDecimal convertToBigDecimal(Object obj)
	/*     */   {
	/* 128 */     if (obj == null)
	/* 129 */       return null;
	/* 130 */     if (obj instanceof BigDecimal) {
	/* 131 */       return ((BigDecimal)obj);
	/*     */     }
	/* 133 */     return new BigDecimal(obj.toString());
	/*     */   }
	/*     */ 
	/*     */   private static Long convertToLong(Object obj)
	/*     */   {
	/* 138 */     if (obj == null)
	/* 139 */       return null;
	/* 140 */     if (obj instanceof Long)
	/* 141 */       return ((Long)obj);
	/* 142 */     if (obj instanceof Integer) {
	/* 143 */       return new Long(((Integer)obj).intValue());
	/*     */     }
	/* 145 */     return new Long(obj.toString());
	/*     */   }
	/*     */ 
	/*     */   private static Timestamp convertToTimestamp(Object obj)
	/*     */   {
	/* 150 */     if (obj == null)
	/* 151 */       return null;
	/* 152 */     if (obj instanceof Timestamp)
	/* 153 */       return ((Timestamp)obj);
	/* 154 */     if (obj instanceof Date) {
	/* 155 */       return new Timestamp(((Date)obj).getTime());
	/*     */     }
	/* 157 */     Timestamp ts = null;
	/* 158 */     String value = obj.toString();
	/*     */ 
	/* 160 */     SimpleDateFormat sdf = null;
	/* 161 */     switch (value.length())
	/*     */     {
	/*     */     case 23:
	/* 163 */       sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
	/* 164 */       break;
	/*     */     case 19:
	/* 166 */       sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
	/* 167 */       break;
	/*     */     case 14:
	/* 169 */       sdf = new SimpleDateFormat("yyyyMMddHHmmss");
	/* 170 */       break;
	/*     */     case 12:
	/* 172 */       sdf = new SimpleDateFormat("HH:mm:ss.SSS");
	/* 173 */       break;
	/*     */     case 10:
	/* 175 */       sdf = new SimpleDateFormat("yyyy/MM/dd");
	/* 176 */       break;
	/*     */     case 8:
	/* 178 */       if (value.indexOf(58) >= 0)
	/* 179 */         sdf = new SimpleDateFormat("HH:mm:ss");
	/*     */       else {
	/* 181 */         sdf = new SimpleDateFormat("yyyyMMdd");
	/*     */       }
	/* 183 */       break;
	/*     */     case 6:
	/* 185 */       sdf = new SimpleDateFormat("HHmmss");
	/* 186 */       break;
	/*     */     default:
	/* 188 */       sdf = new SimpleDateFormat();
	/*     */     }
	/*     */ 
	/*     */     try
	/*     */     {
	/* 193 */       Date dt = sdf.parse(value);
	/* 194 */       ts = new Timestamp(dt.getTime());
	/*     */     } catch (ParseException e) {
	/* 196 */       ts = null;
	/*     */     }
	/*     */ 
	/* 199 */     return ts;
	/*     */   }
}
